#查询数据库

import pymysql
from collections import Counter

dict_data = {}
#可能需要安装 模块 cryptography

def select_data():
    print("开始连接数据库......")

    f = open('./config.txt', 'r')
    sql_ip = f.readline()[:-1]
    sql_port = f.readline()[:]
    print("读取配置文件 ip port：",sql_ip,sql_port)
    f.close()


    connect = pymysql.Connect(
        host=sql_ip,
        port=int(sql_port),
        user='xx',
        passwd='xx',
        db='xx',
        charset='utf8'
    )
    cursor = connect.cursor()

    sql_select = "select addr,port,organization_id,region from  http_proxyvps where status  = 1"
    cursor.execute(sql_select)
    data = cursor.fetchall()  # <class 'tuple'>

    cursor.close()
    connect.close()

    print("查询成功，总数: ",str(len(data)))

    for i in data:
        dict_data[i[2]] = [i[0],i[1],i[3]]
    #print(dict_data)
    return dict_data
select_data()